#if !defined(CASYNCTIMER_H)
#define CASYNCTIMER_H

#ifdef BUILD_WITH_BOOST
#include <boost/asio.hpp>

namespace GSTrader
{
	namespace Util
	{
		typedef struct tagTIMER_INFO
		{
			int iTimerID;
			int iElapse;
			void* pChild;
			boost::asio::deadline_timer* timer;
		} TIMER_INFO, *PTIMER_INFO;

		typedef std::map<int, PTIMER_INFO> MapTimer;

		class TRADE_BASE_API CAsyncTimer
		{
		public:
			CAsyncTimer(boost::asio::io_service& ios);
			virtual ~CAsyncTimer();

			virtual void OnTimer(int iTimerID, const boost::system::error_code& error);
			bool SetTimer(int iTimerID, int iElapse, void* pChild);
			bool KillTimer(int iTimerID);

		private:
			void OnTimerInternal(int iTimerID, const boost::system::error_code& error);
			void RunTimerThread(int iTimerID, int iElapse, void* pChild);
		protected:
			MapTimer m_mapTimer;
			boost::asio::io_service*     m_pIoservice;
		};
	}
}

#endif

#endif // CASYNCTIMER_H